package com.example.dell1.zyftpt_123jwq.model;

import com.example.dell1.zyftpt_123jwq.iface.LogoutIface;
import com.example.dell1.zyftpt_123jwq.iface.LogoutListener;
import com.example.dell1.zyftpt_123jwq.service.LogoutService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by dell1 on 2017/5/25.
 */

public class LogoutModel implements LogoutIface {

    private Retrofit retrofit;

    private String BASEURL = "http://amicool.neusoft.edu.cn/";

    public LogoutModel() {
        retrofit = new Retrofit.Builder().baseUrl(BASEURL).addConverterFactory(GsonConverterFactory.create()).build();
    }

    @Override
    public void getResult(String sessionid, final LogoutListener logoutListener) {
        LogoutService logoutService = retrofit.create(LogoutService.class);
        Call<String> call = logoutService.logout(sessionid);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                if (response.isSuccessful() && response != null) {
                    logoutListener.onResponse(response.body().toString());
                } else
                    logoutListener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {
                logoutListener.onFail(t.toString());
            }
        });
    }


}
